package com.xuwang.service.impl;

import com.xuwang.dto.ComplaintsAcceptDto;
import com.xuwang.pojo.CaseFiling;
import com.xuwang.vo.ComplaintsAcceptInsertVo;
import com.xuwang.vo.ComplaintsAcceptSelectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.xuwang.pojo.ComplaintsAccept;
import com.xuwang.mapper.ComplaintsAcceptMapper;

import java.text.SimpleDateFormat;
import java.util.*;

import com.xuwang.service.ComplaintsAcceptService;

@Service
public class ComplaintsAcceptServiceImpl implements ComplaintsAcceptService {

    @Resource
    private ComplaintsAcceptMapper complaintsAcceptMapper;

    @Override
    public Map<String, Object> deleteByPrimaryKey (String id) {
        String[] idArray = id.split(",");
        List<String> list = new ArrayList<>();
        list.addAll(Arrays.asList(idArray));
        complaintsAcceptMapper.deleteByPrimaryKey(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "删除成功");
        return map;
    }

    @Override
    public int insert (ComplaintsAccept record) {
        return complaintsAcceptMapper.insert(record);
    }

    @Override
    public int insertOrUpdate (ComplaintsAccept record) {
        return complaintsAcceptMapper.insertOrUpdate(record);
    }

    @Override
    //添加更新数据
    public Map<String, Object> insertOrUpdateSelective (ComplaintsAcceptInsertVo complaintsAcceptInsertVo) {
        System.out.println(complaintsAcceptInsertVo);
        ComplaintsAccept complaintsAccept = new ComplaintsAccept();
        BeanUtils.copyProperties(complaintsAcceptInsertVo, complaintsAccept);
        complaintsAccept.setComplaintsId(complaintsAcceptInsertVo.getId());
        complaintsAccept.setSerialNumber((int) System.currentTimeMillis());
        System.out.println(complaintsAccept);
        complaintsAcceptMapper.insertOrUpdateSelective(complaintsAccept);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);   // 前端端分离时，前端人员会首先判断code值是否满足200，如果不是200，则提醒用户失败
        map.put("msg", "新增成功");
        return map;
    }

    @Override
    public int insertSelective (ComplaintsAccept record) {
        return complaintsAcceptMapper.insertSelective(record);
    }

    @Override
    public ComplaintsAccept selectByPrimaryKey (Integer id) {
        return complaintsAcceptMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective (ComplaintsAccept record) {
        return complaintsAcceptMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey (ComplaintsAccept record) {
        return complaintsAcceptMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateBatch (List<ComplaintsAccept> list) {
        return complaintsAcceptMapper.updateBatch(list);
    }

    @Override
    public int updateBatchSelective (List<ComplaintsAccept> list) {
        return complaintsAcceptMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert (List<ComplaintsAccept> list) {
        return complaintsAcceptMapper.batchInsert(list);
    }

    public Map<String, Object> selectAll (int page, int limit, ComplaintsAcceptSelectVo complaintsAcceptSelectVo) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", "查询失败!");
        page = (page - 1) * limit;
        List<ComplaintsAcceptDto> list = complaintsAcceptMapper.selectAll(page, limit, complaintsAcceptSelectVo);
        if (complaintsAcceptSelectVo != null) {
            map.put("code", 0);
            map.put("msg", "查询成功!");
            map.put("pageCount", list.size());
            map.put("data", list);
        }
        return map;
    }

}
